package com.atguigu.petstore.sys.service.impl;

import com.atguigu.petstore.common.util.CaptchaUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.awt.image.BufferedImage;
import java.util.concurrent.TimeUnit;

public class SysCapthcaServiceImpl implements SysCaptchaService{
    @Autowired
    StringRedisTemplate redisTemplate;
    @Override
    public BufferedImage generateCaptcha(String deviceId) {
        String captcha = CaptchaUtil.generateRandomCaptcha(5);

        BufferedImage captchaImg = CaptchaUtil.getCaptchaImg(captcha);
        String key = "user:login" + deviceId + ":" +captcha.toLowerCase();
        redisTemplate.opsForValue().set(key,"111",1, TimeUnit.MINUTES);
        return captchaImg;
    }
}
